dotnet.LoadAssembly (((getdir #scripts) as string)+ "/WindowsControl.dll")

if hBar !=undefined do hBar.close()
hBar = dotNetObject "WindowsControl.ControlBar"
hBar.show()

fn ThePos a b =
(
	format "index:% x:% y:% \n" b.index b.x b.y
)
fn theButton a b =
(
	print  (b.ToString())
)

fn fixSize vMin vMax =
(
	v = vMax - vMin
	if v == 0 then 20 else (abs v)
)

fn AddWindow xMin:0 xMax:100 yMin:0 yMax:100 =
(
	mouseForm = hBar.addForm()
	mouseForm.SetRange xMin yMin xMax yMax
	mouseForm.SetSize (fixSize xMin xMax) (fixSize yMin yMax) 
	mouseForm.setPos 0 0
	dotNet.addEventHandler mouseForm "PosEvent" ThePos
)
fn setPos i x y =
(
	hBar.mouseFormList.Item[i].setPos x y
)	
fn getPos i =
(
	hBar.mouseFormList.Item[i].getPos
)
fn getLoc i =
(
	b = hBar.mouseFormList.Item[i].Target.Location
	format "Location x:% y:% \n" b.x b.y
)
dotNet.addEventHandler hbar "ButtonPress" theButton

-- add new mouse windows to the control list and set ranges.
AddWindow() 
AddWindow xMin:100 xMax:0 yMin:100 yMax:0
AddWindow xMin:100 xMax:-100 yMin:100 yMax:-100
AddWindow xMin:100 xMax:-100 yMin:100 yMax:-100
rng = dotNetObject "WindowsControl.RangeLimit"
--hBar.mouseFormList.Item[0].setPos 0 0